//
//  BKGDCell.m
//  bestkeep
//
//  Created by 毛韶谦 on 2016/11/9.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BKGDCell.h"

NSString *const BKGDTaxCellHelpNotificationKey = @"BKGDTaxCellHelpNotificationKey";

@implementation BKGDCell

-(void)fillData:(id)data {
    
}

-(void)callWithParameter:(id)parameter {
    
}

+(CGFloat)computeHeight:(id)data {
    return 0;
}

@end




#define BKGDTextCellFont [UIFont systemFontOfSize:15]
@implementation BKGDTextCell {
    UILabel *_titleLabel;
    UIImageView *_crossBorderAmoyImgView;//跨境淘
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self) {
        [self initialize];
    }
    return self;
}

-(void)initialize {
    
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.font = BKGDTextCellFont;
    _titleLabel.textColor = RGBACOLOR(64, 64, 64, 1);
    _titleLabel.numberOfLines = 0;
    _titleLabel.lineBreakMode = NSLineBreakByCharWrapping;
    [self.contentView addSubview:_titleLabel];
    
    //全球购标志
    _crossBorderAmoyImgView = [[UIImageView alloc]init];
    _crossBorderAmoyImgView.hidden = YES;
    _crossBorderAmoyImgView.image = [UIImage imageNamed:@"GlobalPurchase"];
    [self.contentView addSubview:_crossBorderAmoyImgView];
    
    [self makeConstraints];
}

-(void)makeConstraints {
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(10);
        make.left.mas_equalTo(12);
        make.right.mas_equalTo(-12);
    }];
    
    [_crossBorderAmoyImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(11);
        make.left.mas_equalTo(self.mas_left).offset(12);
        make.size.mas_equalTo(CGSizeMake(42, 15));
    }];
}

-(void)fillData:(id)data {
    
    [super fillData:data];
    
    if(!data || ![data isKindOfClass:[BKGDObject class]]) {
        return;
    }
    
    BKGDObject *model = data;
    
    _titleLabel.text = model.goodsName;
    //跨境淘
    if ([model.channelType integerValue] == 2) {
        _crossBorderAmoyImgView.hidden = NO;
        [self setFirstLineTextIndentWithContent:_titleLabel firstLineHeadIndent:45];
    }else{
        _crossBorderAmoyImgView.hidden = YES;
        [self setFirstLineTextIndentWithContent:_titleLabel firstLineHeadIndent:0];
    }
}

+(CGFloat)computeHeight:(id)data {
    CGFloat height = 0;
    
    if(!data || ![data isKindOfClass:[BKGDObject class]]) {
        return height;
    }
    
    BKGDObject *model = data;
    NSString *text = @"";
    if ([model.channelType integerValue] == 2) {
        text = [NSString stringWithFormat:@"            %@", model.goodsName];
    }else{
        text = [NSString stringWithFormat:@"%@", model.goodsName];
    }
    
    if([model.goodsName isEqualToString:@""]) {
        return height;
    }
    
    height += 10;
    
    CGSize size = CGSizeMake(CGRectGetWidth([[UIScreen mainScreen] bounds]) - 24, CGFLOAT_MAX);
    CGSize textSize = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: BKGDTextCellFont} context:nil].size;
    height += textSize.height;
    
    return height;
}

//设置首行缩进
-(void)setFirstLineTextIndentWithContent:(UILabel*)contentLabel firstLineHeadIndent:(CGFloat)value
{
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:contentLabel.text];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;
    [paragraphStyle setLineSpacing:3];
    paragraphStyle.firstLineHeadIndent = value;
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [contentLabel.text length])];
    contentLabel.attributedText = attributedString;
}

@end




@implementation BKGDPriceCell {
    UILabel *_vipLabel;
    UILabel *_priceLabel;
    
    BOOL _isVIP;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self) {
        [self initialize];
    }
    return self;
}

-(void)initialize {
    
    _vipLabel = [[UILabel alloc] init];
    _vipLabel.text = @"VIP";
    _vipLabel.font = [UIFont systemFontOfSize:12];//[UIFont boldSystemFontOfSize:12];
    _vipLabel.textColor = [UIColor whiteColor];
    _vipLabel.textAlignment = NSTextAlignmentCenter;
    _vipLabel.backgroundColor = BKGDCellRedColor;
    _vipLabel.layer.masksToBounds = YES;
    _vipLabel.layer.cornerRadius = 2;
    [self.contentView addSubview:_vipLabel];
    
    _priceLabel = [[UILabel alloc] init];
    _priceLabel.lineBreakMode = NSLineBreakByTruncatingTail;
    [self.contentView addSubview:_priceLabel];
}

-(void)makeConstraints {
    
    _vipLabel.hidden = !_isVIP;
    
    [_vipLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.centerY.equalTo(self).offset(2);
        make.size.mas_equalTo(CGSizeMake(30, 15));
    }];
    
    if(_isVIP) {
        
        [_priceLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_vipLabel.mas_right).offset(5);
            make.centerY.equalTo(_vipLabel);
        }];
        
    } else {
        
        [_priceLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(9);
            make.centerY.equalTo(_vipLabel);
        }];
        
    }
    
}

-(void)fillData:(id)data {
    
    [super fillData:data];
    
    if(!data || ![data isKindOfClass:[BKGDObject class]]) {
        return;
    }
    
    BKGDObject *model = data;
    _isVIP = model.userLevel.vipFlag;
//    _isVIP = YES;
    NSString *price1;//会员价格
    NSString *price2;//平台价格
    NSString *marketPrice;//市场价
    NSString *saveing;//节省
    
    if(model.currentSelectSKUObject) {
        price1 = model.currentSelectSKUObject.price1;
        price2 = model.currentSelectSKUObject.price2;
        marketPrice = [NSString stringWithFormat:@"%@%@", BKGDLocalizedString(@"BKGDCellMarketPrice"), model.currentSelectSKUObject.marketPriceStr];
        saveing = model.currentSelectSKUObject.shoppingGuidePriceStr;
    } else {
        price1 = model.price1;
        price2 = model.price2;
        marketPrice = [NSString stringWithFormat:@"%@%@", BKGDLocalizedString(@"BKGDCellMarketPrice"), model.marketPriceStr];
        saveing = model.shoppingGuidePriceStr;
    }
    
    _priceLabel.attributedText = [self priceAttributedString:price1 price2:price2 marketPrice:marketPrice saveing:saveing];
    
    [self makeConstraints];
}

/**
 获取价格显示
 
 @param price1      会员价
 @param price2      平台价格
 @param marketPrice 市场价
 @param saveing     节省
 */
-(NSAttributedString*)priceAttributedString:(NSString*)price1 price2:(NSString*)price2 marketPrice:(NSString*)marketPrice saveing:(NSString*)saveing {
    NSMutableAttributedString *priceAttString;
    //非会员
    if(!_isVIP) {
        
        priceAttString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@  %@", price2, marketPrice]];
        [priceAttString addAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:20], NSForegroundColorAttributeName: BKGDCellRedColor, NSStrikethroughStyleAttributeName: @(NSUnderlineStyleNone)} range:[priceAttString.string rangeOfString:price2]];
        [priceAttString addAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:12], NSForegroundColorAttributeName: BKGDCellLightColor, NSStrikethroughStyleAttributeName: @(NSUnderlineStyleSingle), NSBaselineOffsetAttributeName: @(3)} range:[priceAttString.string rangeOfString:marketPrice]];
        
    } else {
        priceAttString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@  %@", price1, saveing]];
        [priceAttString addAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:20], NSForegroundColorAttributeName: BKGDCellRedColor} range:[priceAttString.string rangeOfString:price1]];
        
        [priceAttString addAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:12], NSForegroundColorAttributeName: BKGDCellYellowColor, NSBaselineOffsetAttributeName: @(3)} range:[priceAttString.string rangeOfString:saveing]];
        
        
    }
    
    
    return priceAttString;
}

+(CGFloat)computeHeight:(id)data {
    CGFloat height = 0;
    
    if(!data || ![data isKindOfClass:[BKGDObject class]]) {
        return height;
    }
    
    BKGDObject *model = data;
    
    if(!model) {
        return height;
    }
    
    height += 34;
    
    return height;
}

@end




@implementation BKGDSubPriceCell {
    UILabel *_vipLabel;
    UILabel *_subPriceLabel;
    UILabel *_becomeVIPLabel;
    
    BOOL _isVIP;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self) {
        [self initialize];
    }
    return self;
}

-(void)initialize {
    
    _vipLabel = [[UILabel alloc] init];
    _vipLabel.text = @"VIP";
    _vipLabel.font = [UIFont boldSystemFontOfSize:12];
    _vipLabel.textColor = [UIColor whiteColor];
    _vipLabel.textAlignment = NSTextAlignmentCenter;
    _vipLabel.backgroundColor = BKGDCellRedColor;
    _vipLabel.layer.masksToBounds = YES;
    _vipLabel.layer.cornerRadius = 2;
    [self.contentView addSubview:_vipLabel];
    
    _subPriceLabel = [[UILabel alloc] init];
    _subPriceLabel.lineBreakMode = NSLineBreakByTruncatingTail;
    [self.contentView addSubview:_subPriceLabel];
    
    _becomeVIPLabel = [[UILabel alloc] init];
    _becomeVIPLabel.font = [UIFont systemFontOfSize:12];
//    _becomeVIPLabel.textColor = [UIColor colorWithRed:0.000 green:0.478 blue:1.000 alpha:1.00];
    _becomeVIPLabel.textColor = ThemeColor;
    _becomeVIPLabel.text = BKGDLocalizedString(@"BKGDCellBecomeVIP");
    _becomeVIPLabel.userInteractionEnabled = YES;
    _becomeVIPLabel.layer.masksToBounds = YES;
    _becomeVIPLabel.layer.cornerRadius = 2;
    _becomeVIPLabel.layer.borderWidth = 1 / [[UIScreen mainScreen] scale];
    _becomeVIPLabel.layer.borderColor = _becomeVIPLabel.textColor.CGColor;
    [self.contentView addSubview:_becomeVIPLabel];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(vipLabelTap:)];
    tap.numberOfTapsRequired = 1;
    [_becomeVIPLabel addGestureRecognizer:tap];
}

-(void)makeConstraints {
    
    _vipLabel.hidden = _isVIP;
    _becomeVIPLabel.hidden = _isVIP;
    
    if(_isVIP) {
        [_subPriceLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self);
            make.left.mas_equalTo(12);
        }];
    } else {
    
        [_vipLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(12);
            make.top.equalTo(self).offset(5);
            make.size.mas_equalTo(CGSizeMake(30, 15));
        }];
        
        [_subPriceLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self);
            make.left.equalTo(_vipLabel.mas_right).offset(5);
        }];
        
        [_becomeVIPLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self);
            make.right.mas_equalTo(-10);
            make.height.mas_equalTo(22);
        }];
    }
    
}

-(void)vipLabelTap:(UIGestureRecognizer*)recognizer {
    if(self.delegate && [self.delegate conformsToProtocol:@protocol(BKGDSubPriceCellDelegate)] && [self.delegate respondsToSelector:@selector(subPriceCellBecomeVIPDidTouched:)]) {
        [self.delegate subPriceCellBecomeVIPDidTouched:self];
    }
}

-(void)fillData:(id)data {
    
    if(!data || ![data isKindOfClass:[BKGDObject class]]) {
        return;
    }
    
    BKGDObject *model = data;
    
    _isVIP = model.userLevel.vipFlag;
//    _isVIP = YES;
    NSString *price1;//会员价格
    NSString *price2;//平台价格
    NSString *marketPrice;//市场价
    NSString *saveing;//节省
    
    if(model.currentSelectSKUObject) {
        price1 = model.currentSelectSKUObject.price1;
        price2 = model.currentSelectSKUObject.price2;
        marketPrice = [NSString stringWithFormat:@"%@%@", BKGDLocalizedString(@"BKGDCellMarketPrice"), model.currentSelectSKUObject.marketPriceStr];
        saveing = model.currentSelectSKUObject.shoppingGuidePriceStr;
    } else {
        price1 = model.price1;
        price2 = model.price2;
        marketPrice = [NSString stringWithFormat:@"%@%@", BKGDLocalizedString(@"BKGDCellMarketPrice"), model.marketPriceStr];
        saveing = model.shoppingGuidePriceStr;
    }
    
    _subPriceLabel.attributedText = [self subPriceAttributedString:price1 price2:price2 marketPrice:marketPrice saveing:saveing];
    
    [self makeConstraints];
}

-(NSAttributedString*)subPriceAttributedString:(NSString*)price1 price2:(NSString*)price2 marketPrice:(NSString*)marketPrice saveing:(NSString*)saveing {
    
    NSMutableAttributedString *subPriceAttString;
    //非会员
    if(!_isVIP) {
        
        subPriceAttString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@  %@", price1, saveing]];
        [subPriceAttString addAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:13], NSForegroundColorAttributeName: BKGDCellRedColor} range:[subPriceAttString.string rangeOfString:price1]];
        [subPriceAttString addAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:12], NSForegroundColorAttributeName: BKGDCellLightColor} range:[subPriceAttString.string rangeOfString:saveing]];
        
    } else {
    
        price2 = [NSString stringWithFormat:@"%@%@", BKGDLocalizedString(@"BKGDCellPlatformPrice"), price2];
        
        subPriceAttString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@  %@", price2, marketPrice]];
        [subPriceAttString addAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:12], NSForegroundColorAttributeName: BKGDCellLightColor, NSStrikethroughStyleAttributeName: @(NSUnderlineStyleNone)} range:[subPriceAttString.string rangeOfString:price2]];
        [subPriceAttString addAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:12], NSForegroundColorAttributeName: BKGDCellLightColor, NSStrikethroughStyleAttributeName: @(NSUnderlineStyleSingle)} range:[subPriceAttString.string rangeOfString:marketPrice]];
    }
    
    return [[NSAttributedString alloc] initWithAttributedString:subPriceAttString];
}

+(CGFloat)computeHeight:(id)data {
    return 30;
}

@end



@implementation BKGDTaxCell {
    UILabel *_taxLabel;
    UILabel *_questionMarkLabel;
    UILabel *_questionLabel;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self) {
        [self initialize];
    }
    
    return self;
}

-(void)initialize {
    _taxLabel = [[UILabel alloc] init];
    _taxLabel.font = [UIFont systemFontOfSize:12];
    _taxLabel.textColor = [UIColor colorWithRed:0.533 green:0.533 blue:0.533 alpha:1.00];
    [self.contentView addSubview:_taxLabel];
    
    _questionLabel = [[UILabel alloc] init];
    _questionLabel.font = [UIFont systemFontOfSize:12];
    _questionLabel.textColor = _taxLabel.textColor;
    _questionLabel.text = BKGDLocalizedString(@"BKGDCellTaxTitle");
    _questionLabel.userInteractionEnabled = YES;
    [self.contentView addSubview:_questionLabel];
    
    NSArray *gestures = self.gestureRecognizers;
    if(gestures && gestures.count > 0) {
        for (UIGestureRecognizer *gecognizer in gestures) {
            [self removeGestureRecognizer:gecognizer];
        }
    }
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(questionLabelTap:)];
    tap.numberOfTapsRequired = 1;
    [_questionLabel addGestureRecognizer:tap];
    
    _questionMarkLabel = [[UILabel alloc] init];
    _questionMarkLabel.font = [UIFont systemFontOfSize:10];
    _questionMarkLabel.text = @"?";
    _questionMarkLabel.textAlignment = NSTextAlignmentCenter;
    _questionMarkLabel.textColor = [UIColor whiteColor];
    _questionMarkLabel.backgroundColor = [UIColor colorWithRed:0.980 green:0.718 blue:0.318 alpha:1.00];
    _questionMarkLabel.layer.masksToBounds = YES;
    _questionMarkLabel.layer.cornerRadius = 5;
    [self.contentView addSubview:_questionMarkLabel];
    
    [self makeConstraints];
}

-(void)makeConstraints {
    [_taxLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.centerY.equalTo(self);
    }];
    
    [_questionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-12);
        make.centerY.equalTo(_taxLabel);
    }];
    
    [_questionMarkLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_questionLabel.mas_left).offset(-5);
        make.centerY.equalTo(_questionLabel);
        make.width.mas_equalTo(10);
        make.height.mas_equalTo(10);
    }];
}

-(void)questionLabelTap:(UIGestureRecognizer*)recognizer {
    [[NSNotificationCenter defaultCenter] postNotificationName:BKGDTaxCellHelpNotificationKey object:nil];
}

-(void)fillData:(id)data {
    if(!data || ![data isKindOfClass:[BKGDObject class]]) {
        return;
    }
    
    BKGDObject *model = data;
    
    NSString *taxString = model.showvipxfs;
    _taxLabel.text = [NSString stringWithFormat:@"%@%@", BKGDLocalizedString(@"BKGDCellTaxMessage"), taxString];
}

+(CGFloat)computeHeight:(id)data {
    return 30;
}

@end





@interface BKGDFeatureDescribeCell()

@property(nonatomic,strong) UILabel *titleLabel;
@property(nonatomic,strong) CALayer *topLineLayer;

@end

@implementation BKGDFeatureDescribeCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self) {
        [self initialize];
    }
    return self;
}

-(void)initialize {
    
    _topLineLayer = [[CALayer alloc] init];
    _topLineLayer.backgroundColor = [UIColor colorWithRed:0.949 green:0.949 blue:0.949 alpha:1.00].CGColor;
    _topLineLayer.frame = CGRectMake(12, 0, CGRectGetWidth([[UIScreen mainScreen] bounds]) - 12, 1);
    [self.contentView.layer addSublayer:_topLineLayer];
    
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
    _titleLabel.numberOfLines = 0;
    _titleLabel.textColor = BKGDCellLightColor;
    [self.contentView addSubview:_titleLabel];
}

-(void)layoutSubviews {
    [super layoutSubviews];
    
    _topLineLayer.frame = CGRectMake(0, 0, CGRectGetWidth([[UIScreen mainScreen] bounds]), 1);
    _titleLabel.frame = CGRectMake(12, 13, CGRectGetWidth([[UIScreen mainScreen] bounds]) - 20, CGRectGetHeight(self.frame) - 13 - 13);
}

-(void)fillData:(id)data {
    if(!data || ![data isKindOfClass:[NSString class]]) {
        return;
    }

    _titleLabel.attributedText = [BKGDFeatureDescribeCell attributeString:data];
}

+(NSAttributedString*)attributeString:(NSString*)text {
    
    UIFont *font = [UIFont systemFontOfSize:13];
    
    CGSize size = [text boundingRectWithSize:CGSizeMake(CGRectGetWidth([[UIScreen mainScreen] bounds]) - 20, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: font} context:nil].size;
    
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    style.lineSpacing = 3;
    if(size.height > font.lineHeight) {
        style.firstLineHeadIndent = font.lineHeight * 2;
    } else {
        style.firstLineHeadIndent = 0;
    }
    
    NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] init];
    [attString setAttributedString:[[NSAttributedString alloc] initWithString:text attributes:@{NSFontAttributeName: font, NSParagraphStyleAttributeName: style}]];
    return attString;
}

+(CGFloat)computeHeight:(id)data {
    CGFloat height = 0;
    if(!data || ![data isKindOfClass:[NSString class]]) {
        return height;
    }
    
    height += 13;
    
    NSString *str = (NSString*)data;
    
    NSAttributedString *attString = [BKGDFeatureDescribeCell attributeString:str];
    
    NSDictionary *att = [attString attributesAtIndex:0 effectiveRange:nil];
    NSFont *font = att[NSFontAttributeName];
    NSParagraphStyle *style = att[NSParagraphStyleAttributeName];
    
    CGSize size = [str boundingRectWithSize:CGSizeMake(CGRectGetWidth([[UIScreen mainScreen] bounds]) - 20, CGFLOAT_MAX) options: NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: font, NSParagraphStyleAttributeName: style} context:nil].size;
    
    height += size.height;
    
    height += 13;
    
    return height;
}

@end





@implementation BKGDActivityCollectionViewCell

-(instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if(self) {
        [self initialize];
    }
    return self;
}

-(void)initialize {
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.font = [UIFont systemFontOfSize:10];
    _titleLabel.textColor = BKGDCellRedColor;
    _titleLabel.textAlignment = NSTextAlignmentCenter;
    _titleLabel.layer.masksToBounds = YES;
    _titleLabel.layer.cornerRadius = 2;
    _titleLabel.layer.borderColor = BKGDCellRedColor.CGColor;
    _titleLabel.layer.borderWidth = 1 / [[UIScreen mainScreen] scale];
    [self.contentView addSubview:_titleLabel];
    
    _subTitleLabel = [[UILabel alloc] init];
    _subTitleLabel.font = [UIFont systemFontOfSize:11];
    _subTitleLabel.textColor = BKGDCellLightColor;
    _subTitleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
    [self.contentView addSubview:_subTitleLabel];
}

-(void)layoutSubviews {
    [super layoutSubviews];
    
    CGSize size = [_titleLabel.text sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:10]}];
    _titleLabel.frame = CGRectMake(0, 0, size.width + 4, 16);
    
    _subTitleLabel.frame = CGRectMake(CGRectGetMaxX(_titleLabel.frame) + 5, CGRectGetMinX(_titleLabel.frame), CGRectGetWidth(self.frame) - CGRectGetMaxX(_titleLabel.frame) - 20, 16);
}

@end

NSString *const BKGDActivityCellIdentifier = @"BKGDActivityCellIdentifier";
@interface BKGDPromotionCell()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>

@end

@implementation BKGDPromotionCell {
    UICollectionView *_collectionView;
    NSArray<NSString*> *_items;
    NSArray<BKGDKeyValueObject*> *_promotions;
    
    UILabel *_flagLabel;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self) {
        [self initialize];
    }
    
    return self;
}

-(void)initialize {
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    layout.minimumLineSpacing = 5;
    layout.minimumInteritemSpacing = 5;
    
    _collectionView = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:layout];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.scrollEnabled = NO;
    _collectionView.backgroundColor = [UIColor clearColor];
    _collectionView.userInteractionEnabled = NO;
    [_collectionView registerClass:[BKGDActivityCollectionViewCell class] forCellWithReuseIdentifier:BKGDActivityCellIdentifier];
    [self.contentView addSubview:_collectionView];
    
    _flagLabel = [[UILabel alloc] init];
    _flagLabel.font = [UIFont systemFontOfSize:12];
    _flagLabel.backgroundColor = BKGDCellRedColor;
    _flagLabel.textColor = [UIColor whiteColor];
    _flagLabel.textAlignment = NSTextAlignmentCenter;
    _flagLabel.text = BKGDLocalizedString(@"BKGDCellPromotion");
    _flagLabel.layer.masksToBounds = YES;
    _flagLabel.layer.cornerRadius = 2;
    [self.contentView addSubview:_flagLabel];
}

-(void)layoutSubviews {
    [super layoutSubviews];
    
//    _flagLabel.frame = CGRectMake(12, 10, 16, 16);
    _flagLabel.frame = CGRectMake(12, 14.5, 16, 16);
    
    _collectionView.frame = CGRectMake(CGRectGetMaxX(_flagLabel.frame) + 10, CGRectGetMinY(_flagLabel.frame), CGRectGetWidth(self.frame) - CGRectGetMaxX(_flagLabel.frame) - 20, CGRectGetHeight(self.frame) - 20);
}

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 2;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    if(section == 0) {
        return _items.count;
    } else if(section == 1) {
//        return _promotions.count;
        NSInteger count;
        if(_items.count > 0) {
            count = _promotions.count > 1 ? 1 : _promotions.count;
        } else {
            count = _promotions.count > 2 ? 2 : _promotions.count;
        }
        return count;
    }
    
    return 0;
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
    
    CGSize size;
    if(section == 0){
        size = CGSizeZero;
    } else {
        if(_items.count) {
            size = CGSizeMake(CGRectGetWidth(collectionView.frame), 5);
        } else {
            size = CGSizeZero;
        }
    }
    
    return size;
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    CGSize size;
    
    if(indexPath.section == 0) {
        
        NSString *text = _items[indexPath.row];
        
        size = [text sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:10]}];
        size.width += 4;
        size.height = 16;
        
    } else if(indexPath.section == 1) {
        
        size = CGSizeMake(CGRectGetWidth(collectionView.frame), 16);
    }
    
    return size;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    BKGDActivityCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:BKGDActivityCellIdentifier forIndexPath:indexPath];
    
    if([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0) {
        [self configCell:cell atIndexPath:indexPath];
    }
    
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
    [self configCell:(BKGDActivityCollectionViewCell*)cell atIndexPath:indexPath];
}

-(void)configCell:(BKGDActivityCollectionViewCell*)cell atIndexPath:(NSIndexPath*)indexPath {
    
    if(indexPath.section == 0) {
        cell.titleLabel.text = _items[indexPath.row];
        cell.subTitleLabel.text = @"";
    } else if(indexPath.section == 1) {
        cell.titleLabel.text = _promotions[indexPath.row].value;
        cell.subTitleLabel.text = _promotions[indexPath.row].key;
    }
}


-(void)fillData:(id)data {
    if(!data || ![data isKindOfClass:[BKGDObject class]]) {
        return;
    }
    
    [_collectionView.collectionViewLayout invalidateLayout];
    
    BKGDObject *model = data;
    
    _items = model.activities;
    _promotions = model.promotions;
    
    [_collectionView reloadData];
}

+(CGFloat)computeHeight:(id)data {
    CGFloat height = 0;
    if(!data || ![data isKindOfClass:[BKGDObject class]]) {
        return height;
    }
    //2017.3.7
    BKGDObject *model = data;
    
//    height += 10;
    height += 19;
    
    if(model.activities.count > 0) {
        height += 16;
        height += 5;
    }
    
    if(model.promotions.count) {
        NSInteger count;
        if(model.activities.count > 0) {
            count = model.promotions.count > 1 ? 1 : model.promotions.count;
        } else {
            count = model.promotions.count > 2 ? 2 : model.promotions.count;
        }
        height += 21 * count;
    }
    
    height += 5;
    
    return height;
    
//    return 45;
}

@end



@implementation BKGDSendAddressCell {
    UILabel *_titleLabel;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self) {
        [self initialize];
    }
    
    return self;
}

-(void)initialize {
    
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.font = [UIFont systemFontOfSize:15];
    _titleLabel.textColor = BKGDCellGrayColor;
    _titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
    [self.contentView addSubview:_titleLabel];
}

-(void)layoutSubviews {
    [super layoutSubviews];
    
    _titleLabel.frame = CGRectMake(12, 0, CGRectGetWidth(self.frame) - 24, CGRectGetHeight(self.frame));
}

-(void)fillData:(id)data {
    if(!data || ![data isKindOfClass:[BKGDObject class]]) {
        return;
    }
    
    BKGDObject *model = data;
    
    NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] init];
    [attString appendAttributedString:[[NSAttributedString alloc] initWithString:BKGDLocalizedString(@"发货地  ") attributes:@{NSForegroundColorAttributeName: BKGDCellGrayColor}]];
    if ([model.sendAddress isEqualToString:@""] || model.sendAddress == nil) {
        [attString appendAttributedString:[[NSAttributedString alloc] initWithString:model.ckName  attributes:@{NSForegroundColorAttributeName: BKGDCellGrayColor}]];
    }else{
        [attString appendAttributedString:[[NSAttributedString alloc] initWithString:model.sendAddress attributes:@{NSForegroundColorAttributeName: BKGDCellGrayColor}]];
    }
    _titleLabel.attributedText = attString;
    
}

+(CGFloat)computeHeight:(id)data {
    return 45;
}

@end


@implementation BKGD7daysReturnCell {
    UILabel *_returnLabel;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = RGBACOLOR(250, 250, 250, 1);
        [self initialize];
    }
    return self;
}

- (void)initialize {
    _returnLabel = [[UILabel alloc] init];
    _returnLabel.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:_returnLabel];
}

-(void)layoutSubviews {
    [super layoutSubviews];
    
    _returnLabel.frame = CGRectMake(12, 0, CGRectGetWidth(self.frame) - 24, CGRectGetHeight(self.frame));
}

-(void)fillData:(id)data {
    if(!data || ![data isKindOfClass:[BKGDObject class]]) {
        return;
    }
    
    BKGDObject *model = data;
    
    NSString *returnStr = @"";
    UIImage *img;
    if ([model.canReturnSaled integerValue] == 0) {
        returnStr= @" 不支持7天无理由退货";
        img = [UIImage imageNamed:@"sevenDaysreturn_no"];
    }else{
        returnStr = @" 支持7天无理由退货";
        img = [UIImage imageNamed:@"sevenDaysreturn"];
    }
    
    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:returnStr];
    [attri addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:136/255.f green:136/255.f blue:136/255.f alpha:1] range:NSMakeRange(0, returnStr.length)];
    [attri addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(0, returnStr.length)];
    
    NSTextAttachment *attach = [[NSTextAttachment alloc] init];
    attach.image = img;
    attach.bounds = CGRectMake(0, -3, img.size.width, img.size.height);
    NSAttributedString *attr = [NSAttributedString attributedStringWithAttachment:attach];
    
    [attri insertAttributedString:attr atIndex:0];
    
    _returnLabel.attributedText = attri;
    
}

+ (CGFloat)computeHeight:(id)data {
    return 25;
}

@end


@implementation BKGDSKUCell {
    UILabel *_titleLabel;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self) {
        [self initialize];
    }
    
    return self;
}

-(void)initialize {
    
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.textColor = BKGDCellGrayColor;
    _titleLabel.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:_titleLabel];
    
    [self makeConstaints];
}

-(void)makeConstaints {
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.mas_equalTo(12);
        make.bottom.mas_equalTo(0);
        make.right.mas_equalTo(-12);
    }];
}

-(void)fillData:(id)data {
    if(!data || ![data isKindOfClass:[NSString class]]) {
        _titleLabel.text = BKGDLocalizedString(@"BKGDCellSKUCellTitle");
        return;
    }
    
    _titleLabel.text = data;
}

+(CGFloat)computeHeight:(id)data {
    return 45;
}

@end




@implementation BKGDQuotaCell {
    UIImageView *_markImageView;
    UILabel *_titleLabel;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self) {
        [self initialize];
    }
    
    return self;
}

-(void)initialize {
    
    self.contentView.backgroundColor = [UIColor colorWithRed:0.996 green:0.984 blue:0.925 alpha:1.00];
    
    _markImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"BKGDExclamationMark"]];
    _markImageView.contentMode = UIViewContentModeCenter;
    [self.contentView addSubview:_markImageView];
    
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.font = [UIFont systemFontOfSize:10];
    _titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
    _titleLabel.textColor = BKGDCellGrayColor;
    [self.contentView addSubview:_titleLabel];
    
    [self makeConstraints];
}

-(void)makeConstraints {
    [_markImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.centerY.equalTo(self.contentView);
        make.size.mas_equalTo(CGSizeMake(12, 12));
    }];
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView.center.y).offset(0);
        make.left.equalTo(_markImageView.mas_right).offset(3);
        make.right.mas_equalTo(self.contentView.mas_right).offset(-12);
    }];
}

-(void)fillData:(id)data {
    if(!data || ![data isKindOfClass:[NSString class]]) {
        return;
    }
    
    _titleLabel.text = data;
}

+(CGFloat)computeHeight:(id)data {
    return 20;
}

@end



@implementation BKGDPTitleCell {
    UILabel *_proTitleLabel;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self) {
        [self initialize];
    }
    
    return self;
}

-(void)initialize {
    
    _proTitleLabel = [[UILabel alloc] init];
    _proTitleLabel.font = [UIFont systemFontOfSize:14];
    _proTitleLabel.textColor = BKGDCellGrayColor;
    [_proTitleLabel sizeToFit];
    [self.contentView addSubview:_proTitleLabel];
    [_proTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(12);
        make.left.equalTo(self).offset(12);
        make.right.equalTo(self).offset(-12);
    }];
}

-(void)fillData:(id)data {
    if(!data || ![data isKindOfClass:[NSString class]]) {
        return;
    }
    
    _proTitleLabel.font = [UIFont systemFontOfSize:14];
    _proTitleLabel.textColor = BKGDCellGrayColor;
    _proTitleLabel.text = data;
}

+(CGFloat)computeHeight:(id)data {
    return 35;
}

@end






@implementation BKGDPropertyCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self) {
        [self initialize];
    }
    return self;
}

-(void)initialize {
    
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.font = [UIFont systemFontOfSize:13];
    _titleLabel.textColor = [UIColor grayColor];
    _titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
    [self.contentView addSubview:_titleLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.mas_equalTo(12);
        make.bottom.mas_equalTo(0);
        make.width.mas_equalTo(80);
    }];
    
    _contentLabel = [[UILabel alloc] init];
    _contentLabel.font = [UIFont systemFontOfSize:12];
    _contentLabel.textColor = [UIColor grayColor];
    _contentLabel.lineBreakMode = NSLineBreakByWordWrapping;
    _contentLabel.numberOfLines = 0;
    [self.contentView addSubview:_contentLabel];
    [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.equalTo(_titleLabel.mas_right).offset(12);
        make.bottom.mas_equalTo(0);
        make.right.mas_equalTo(-12);
    }];
}

-(void)fillData:(id)data {
    if(!data || ![data isKindOfClass:[BKGDKeyValueObject class]]) {
        return;
    }
    
    BKGDKeyValueObject *property = data;
    
    NSString *name = property.key;
    NSString *value = property.value;
    
    _titleLabel.text = name;
    _contentLabel.text = value;
}

+(CGFloat)computeHeight:(id)data {
    
    if(!data || ![data isKindOfClass:[BKGDKeyValueObject class]]) {
        return 24;
    }
    
    
    BKGDKeyValueObject *property = data;
    
    if ([property.key isEqualToString:@""] && [property.value isEqualToString:@""]) {
        return 11;
    }
    
    CGFloat height = 0;
    
    NSString *value = property.value;
    
    if(value && ![value isEqualToString:@""]) {
        CGSize size = CGSizeMake([[UIScreen mainScreen] bounds].size.width - 120, CGFLOAT_MAX);
        CGFloat contentHeight = [value boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:12]} context:nil].size.height;
        
        contentHeight = contentHeight < height ? height : contentHeight;
        
        height += contentHeight;
    } else {
        height += 14;
    }
    
    height += 10;//留白
    
    return height;
}

@end



@implementation BKGDEvaluatTitleCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self) {
        [self initialize];
    }
    return self;
}

-(void)initialize {
    
    _leftLabel = [[UILabel alloc] init];
    _leftLabel.font = [UIFont systemFontOfSize:15];
    _leftLabel.textColor = [UIColor colorWithRed:0.251 green:0.251 blue:0.251 alpha:1.00];
    [self.contentView addSubview:_leftLabel];
    [_leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(12.5);
        make.left.mas_equalTo(12);
        make.height.equalTo(@20);
    }];
    
    _rightBtn = [[UIButton alloc] init];
    _rightBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [_rightBtn setImage:[UIImage imageNamed:@"TableViewArrow"] forState:UIControlStateNormal];
    [_rightBtn setTitle:BKGDLocalizedString(@"BKGDMainEvaluationEmpty") forState:UIControlStateNormal];
    [_rightBtn setTitleColor:[UIColor colorWithRed:0.682 green:0.686 blue:0.690 alpha:1.00] forState:UIControlStateNormal];
    [_rightBtn layoutButtonWithEdgeInsetsStyle:XNButtonEdgeInsetsStyleRight imageTitleSpace:4];
    
    [_rightBtn addTarget:self action:@selector(toEvaluationPage) forControlEvents:UIControlEventTouchUpInside];

    [self.contentView addSubview:_rightBtn];
    [_rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_leftLabel);
        make.right.mas_equalTo(-12);
        make.width.equalTo(@80);
    }];
    
}

-(void)toEvaluationPage {
    [[NSNotificationCenter defaultCenter] postNotificationName:@"BKGDManagerViewControllerMoveToPageNotificationKey" object:@(2)];
}

-(void)fillData:(id)data {
    _leftLabel.text = BKGDLocalizedString(@"BKGDMainEvaluation");
}

+(CGFloat)computeHeight:(id)data {
    return 45;
}

@end



@interface BKGDEvaluationCell()<BKGDImagesViewDelegate, WUImageBrowseViewDelegate>

@property(nonatomic,strong) UIView *topLineView;

@property(nonatomic,strong) BKGDImagesView *imagesView;

@end

@implementation BKGDEvaluationCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self) {
        [self initialize];
    }
    return self;
}

-(void)initialize {
    
    _topLeftLabel = [[UILabel alloc] init];
    _topLeftLabel.font = [UIFont systemFontOfSize:15];
    _topLeftLabel.textColor = [UIColor colorWithRed:0.251 green:0.251 blue:0.251 alpha:1.00];
    [self.contentView addSubview:_topLeftLabel];
    [_topLeftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(12.5);
        make.left.mas_equalTo(12);
        make.height.equalTo(@20);
    }];
    
    _topRightLabel = [[UILabel alloc] init];
    _topRightLabel.font = [UIFont systemFontOfSize:14];
    _topRightLabel.textColor = [UIColor colorWithRed:0.682 green:0.686 blue:0.690 alpha:1.00];
    [self.contentView addSubview:_topRightLabel];
    [_topRightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_topLeftLabel);
        make.right.mas_equalTo(-12);
    }];
    
    _topLineView = [[UIView alloc] init];
    _topLineView.backgroundColor = [UIColor colorWithRed:0.871 green:0.871 blue:0.871 alpha:1.00];
    [self.contentView addSubview:_topLineView];
    [_topLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(45);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(1);
    }];
    
    _avatarImageView = [[UIImageView alloc] init];
    _avatarImageView.contentMode = UIViewContentModeScaleToFill;
    _avatarImageView.clipsToBounds = YES;
    _avatarImageView.layer.masksToBounds = YES;
    _avatarImageView.layer.cornerRadius = 17;
    [self.contentView addSubview:_avatarImageView];
    [_avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_topLineView.mas_bottom).offset(15);
        make.left.mas_equalTo(12);
        make.size.mas_equalTo(CGSizeMake(34, 34));
    }];
    
    _gradView = [[BKGDGradeView alloc] init];
    _gradView.allowSelection = NO;
    [self.contentView addSubview:_gradView];
    [_gradView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_avatarImageView);
        make.right.mas_equalTo(-12);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(20);
    }];
    
    _infoLabel = [[UILabel alloc] init];
    _infoLabel.font = [UIFont systemFontOfSize:14];
    _infoLabel.textColor = [UIColor colorWithRed:64/255.0 green:64/255.0 blue:64/255.0 alpha:1.00];
    _infoLabel.numberOfLines = 0;
    [self.contentView addSubview:_infoLabel];
    [_infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_avatarImageView.mas_right).offset(8);
        make.centerY.equalTo(_avatarImageView);
        make.width.mas_equalTo(140);
    }];
    
    _contentLabel = [[UILabel alloc] init];
    _contentLabel.font = [UIFont systemFontOfSize:13];
    _contentLabel.textColor = [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.00];
    _contentLabel.numberOfLines = 2;
    [self.contentView addSubview:_contentLabel];
    [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_avatarImageView.mas_bottom).offset(10);
        make.left.mas_equalTo(12);
        make.right.mas_lessThanOrEqualTo(-12);
    }];
    
    _propertyLabel = [[UILabel alloc] init];
    _propertyLabel.font = [UIFont systemFontOfSize:12];
    _propertyLabel.textColor = [UIColor colorWithRed:178/255.0 green:178/255.0 blue:178/255.0 alpha:1.00];
    [self.contentView addSubview:_propertyLabel];
    
    _bottomButton = [[UIButton alloc] init];
    [_bottomButton setTitle:BKGDLocalizedString(@"BKGDCellAllEvaluation") forState:UIControlStateNormal];
    [_bottomButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [_bottomButton.titleLabel setFont:[UIFont systemFontOfSize:12]];
    _bottomButton.layer.masksToBounds = YES;
    _bottomButton.layer.cornerRadius = 2;
    _bottomButton.layer.borderColor = [UIColor colorWithRed:0.561 green:0.565 blue:0.569 alpha:1.00].CGColor;
    _bottomButton.layer.borderWidth = 0.6;
    [_bottomButton addTarget:self action:@selector(bottomButtonTouchUpInside:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_bottomButton];
    
    _imagesView = [[BKGDImagesView alloc] initWithAutoLayout:NO];
    _imagesView.delegate = self;
    [self.contentView addSubview:_imagesView];
}

-(void)fillData:(id)data {
    
    if(!data || ![data isKindOfClass:[BKGDEvaluationGeneralObject class]]) {
        return;
    }
    
    BKGDEvaluationGeneralObject *evaluationGeneral = data;
    
    if(!evaluationGeneral) {
        return;
    }
    
    if(!evaluationGeneral.evaluation.userName) {
        evaluationGeneral.evaluation.userName = @"";
    }
    
    _gradView.gradeValue = evaluationGeneral.evaluation.scoringGrades;
    
    _topLeftLabel.text = [NSString stringWithFormat:@"%@(%ld)", BKGDLocalizedString(@"BKGDCellGoodsEvaluation"), (long)evaluationGeneral.total];
    _topRightLabel.text = [NSString stringWithFormat:@"%@%ld%%", BKGDLocalizedString(@"BKGDCellSatisfaction"), (long)evaluationGeneral.haopingPct];
    //pic_newGoods
    [_avatarImageView load:evaluationGeneral.evaluation.userPhoto placeholderImage:[UIImage imageNamed:@"BKGDAvatarDefault"]];
    
    NSMutableAttributedString *infoAttString = [[NSMutableAttributedString alloc] init];
    [infoAttString appendAttributedString:[[NSAttributedString alloc] initWithString:evaluationGeneral.evaluation.userName attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:14], NSForegroundColorAttributeName: [UIColor colorWithRed:64/255.0 green:64/255.0 blue:64/255.0 alpha:1.00]}]];
    
    NSString *createData = [NSString stringWithFormat:@"\n%@",evaluationGeneral.evaluation.createdDateStr];
    [infoAttString appendAttributedString:[[NSAttributedString alloc] initWithString:createData attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:10], NSForegroundColorAttributeName: [UIColor colorWithRed:178/255.0 green:178/255.0 blue:178/255.0 alpha:1.00]}]];
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineSpacing = 2;
    [infoAttString addAttributes:@{NSParagraphStyleAttributeName: paragraphStyle} range:(NSRange){0, infoAttString.string.length}];
    
    _infoLabel.attributedText = infoAttString;
    
    //    _contentLabel.attributedText = [BKGDEvaluationCell getContentAttString:evaluationGeneral.evaluation];
    _contentLabel.text = evaluationGeneral.evaluation.experiences;
    
    NSArray<BKGDEvaluPropertyObject*> *props = evaluationGeneral.evaluation.propRelStrs;
    if(props && props.count > 0) {
        NSString *propsString = [BKGDEvaluationCell getPropsString:props];
        _propertyLabel.text = propsString;
        [_propertyLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_contentLabel.mas_bottom).offset(10);
            make.left.equalTo(_contentLabel);
            make.right.equalTo(_contentLabel);
            make.height.mas_equalTo(_propertyLabel.font.lineHeight);
        }];
    } else {
        [_propertyLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_contentLabel.mas_bottom);
            make.left.equalTo(_contentLabel);
        }];
    }
    
    if(evaluationGeneral.evaluation.images && evaluationGeneral.evaluation.images.count > 0)  {
        NSMutableArray<NSString*> *images = [NSMutableArray array];
        for (NSDictionary<NSString*, NSString* > *item in evaluationGeneral.evaluation.images) {
            [images addObject:item[@"image"]];
        }
        
        _imagesView.images = images;
        
        [_imagesView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_propertyLabel.mas_bottom).offset(10);
            make.left.mas_equalTo(1);
            make.right.mas_equalTo(-1);
            make.height.mas_equalTo(64);
        }];
        
        [_bottomButton mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_imagesView.mas_bottom).offset(10);
            make.centerX.mas_equalTo(0);
            make.size.mas_equalTo(CGSizeMake(90, 22));
        }];
    } else {
        [_bottomButton mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_propertyLabel.mas_bottom).offset(10);
            make.centerX.mas_equalTo(0);
            make.size.mas_equalTo(CGSizeMake(90, 22));
        }];
    }
}

/**
 根据数据生成要显示的评论信息
 */
//+(NSAttributedString*)getContentAttString:(BKGDEvaluationModel*)evaluation {
//
//    NSString *content = evaluation.experiences;
//
//    NSArray<BKGDProperty*> *props = evaluation.propRelStrs;
//    NSString *propsString;
//    if(props && props.count > 0) {
//        propsString = [NSString stringWithFormat:@"\n\n%@", [self getPropsString:props]];
//    }
//
//    NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] init];
//    [attString appendAttributedString:[[NSAttributedString alloc] initWithString:content attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:12], NSForegroundColorAttributeName: [UIColor colorWithRed:0.533 green:0.533 blue:0.533 alpha:1.00]}]];
//
//    if(propsString) {
//        [attString appendAttributedString:[[NSAttributedString alloc] initWithString:propsString attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:12], NSForegroundColorAttributeName: [UIColor colorWithRed:0.698 green:0.698 blue:0.698 alpha:1.00]}]];
//    }
//
//    return attString;
//}

/**
 获取显示的商品参数
 */
+(NSString*)getPropsString:(NSArray<BKGDEvaluPropertyObject*>*)props {
    
    NSMutableString *str = [NSMutableString string];
    
    for (BKGDEvaluPropertyObject *prop in props) {
        [str appendFormat:@"%@:%@  ", prop.proName, prop.proValue];
    }
    
    return str;
}

-(void)bottomButtonTouchUpInside:(UIButton*)sender {
    if(self.delegate && [self.delegate conformsToProtocol:@protocol(BKGDEvaluationCellDelegate)]) {
        [self.delegate evaluationCell:self bottomButtonTouched:sender];
    }
}

#pragma -mark 点击图片
-(void)imagesView:(BKGDImagesView *)view didSelectAtIndex:(NSInteger)index atImage:(UIImage *)image {
    
    if(!image) {
        return;
    }
    
    WUImageBrowseView *ibView = [[WUImageBrowseView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    ibView.delegate = self;
    ibView.currentPage = index;
    ibView.images = view.images;
    ibView.pageControlStyle = WUPageControlStyleUILabel;
    
    UIWindow *backView = [[UIApplication sharedApplication] keyWindow];
    
    CGRect startFrame = [view rectToScreenAtItemIndex:index];
    
    [ibView show:backView startFrame:startFrame foregroundImage:image];
}

#pragma -mark WUImageBrowser delegate

-(CGRect)imageBrowseView:(WUImageBrowseView *)view willCloseAtIndex:(NSInteger)index {
    CGRect rect = [_imagesView rectToScreenAtItemIndex:index];
    
    return rect;
}


+(CGFloat)computeHeight:(id)data {
    
    if(!data || ![data isKindOfClass:[BKGDEvaluationGeneralObject class]]) {
        return 0;
    }
    
    BKGDEvaluationGeneralObject *evaluationGeneral = data;
    
    if(!evaluationGeneral) {
        return 0;
    }
    
    CGFloat height = 93;
    
    UIFont *font = [UIFont systemFontOfSize:13];
    //    NSString *string = [self getContentAttString :evaluationGeneral.evaluation].string;
    NSString *string = evaluationGeneral.evaluation.experiences;
    CGSize size = CGSizeMake([[UIScreen mainScreen] bounds].size.width - 20, CGFLOAT_MAX);
    CGSize contentSize = [string boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : font} context:nil].size;
    
    if(contentSize.height > [font lineHeight] * 2) {
        height += [font lineHeight] * 2;
    } else {
        height += contentSize.height;
    }
    
    if(evaluationGeneral.evaluation.propRelStrs && evaluationGeneral.evaluation.propRelStrs.count > 0) {
        height += 10;
        height += font.lineHeight;
    }
    
    if(evaluationGeneral.evaluation.images && evaluationGeneral.evaluation.images.count > 0) {
        height += 10;
        height += 64;
    }
    
    height += 10;//间距
    height += 22;//按钮高度
    height += 20;//底部留白
    
    return height;
}


@end
